<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="renderer" content="webkit" />
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<meta name="App-Config" content="fullscreen=yes,useHistoryState=yes,transition=yes" />
		<meta content="yes" name="apple-mobile-web-app-capable" />
		<meta content="yes" name="apple-touch-fullscreen" />
		<meta content="telephone=no,email=no" name="format-detection" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>全民经纪人</title>
	</head>
	<link href="../c/allpeople.css" rel="stylesheet" />
	<body>
		<div class="main" style="display: none;">
			<div class="nav_ti">
				<p><span style="font-size: 1.2rem;">达人</span><small style="display: block;"></small></p>
				<p><span>工会</span><small></small></p>
				<p><span>机构</span><small></small></p>
			</div>
			<div class="picls">
				<img src=" ../i/addpic/daren.png" class="pic" style="display: block;" as="a" />
				<img src="../i/addpic/gh.png" class="pic" as="b" />
				<img src="../i/addpic/jg.png" class="pic" as="b" />
			</div>
			<p class="tiitle">
				<img src="../i/addpic/as.png" />
				<span>达人培训课程</span>
				<img src="../i/addpic/as.png" />
			</p>
			<div class="allpeople_Tex">
				<img src="../i/addpic/darens.png" onclick="_url({url:'rearen',title:'达人培训课程'})" style="display: block;">
				<img src="../i/addpic/ghui.png" onclick="_url({url:'darengh',title:'达人工会培训课程'})">
				<img src="../i/addpic/jigou.png" onclick="_url({url:'darenjg',title:'达人机构培训课程'})">
			</div>
			<button class="btnsuer">申请并支付<small style="margin-left: 0.5rem;"></small></button>
			<div class="payas">
				<p>选择支付方式</p>
				<p class="pay">微信</p>
				<p class="pay">支付宝</p>
				<p class="payclose">取消</p>
			</div>
		</div>

		<div class="bsimg" style="display: none;">
			<img src="">
			<p>双击图片取消观看图片</p>
		</div>
	</body>
</html>
<script src="../j/api.js"></script>
<script src="../j/jquery-3.3.1.min.js"></script>
<script>
	function urlsa() {
		var imglen = $("img").length;
		var picurls = picurl + "/addpic";
		for (var i = 0; i < imglen; i++) {
			var tpl = $("img").eq(i).attr("src");
			tpls = tpl.replace("../i/addpic", picurls);
			$("img").eq(i).attr("src", tpls);
		}
	}


	function time() {
		var t;
		var i = 0;
		// 监听支付事件
		api.addEventListener({
			name: '_pay'
		}, function(ret, err) {
			_alert(ret.value.msg);
			_close();
		});
		t = window.setInterval(function() {
			i++;
			if (i >= 4) {
				clearInterval(t);
				$(".bsimg p").css("opacity", "0");
			} else {
				$(".bsimg p").css("opacity", "1");
			}
		}, 1000)
	}
	$(".nav_ti").on("click", "p", function() {
		$(".nav_ti p small").css("display", "none");
		$(".nav_ti p span").css("font-size", "0.9375rem");
		$(this).children("small").css("display", "block");
		$(this).children("span").css("font-size", "1.2rem");
		$(".pic").hide();
		$(".pic").attr("as", "b");
		$(".pic").eq($(this).index()).show();
		$(".allpeople_Tex img").css("display", "none");
		$(".allpeople_Tex img").eq($(this).index()).css("display", "block");
		$(".pic").eq($(this).index()).attr("as", "a");
		$(".tiitle span").text("" + $(this).children("span").eq(0).text() + "培训课程");
		var ind = $(this).index();
		_ajax('member/vip_money', function(ret, err) {
			if (ret) {
				$(".btnsuer small").text("(￥" + ret[ind].money + "元)");
			}
		})
	})
	$(".mkbg").on("click", "p", function() {
		var src = $(".picls img[as=a]").index();
		$(".bsimg img").css("margin-top", "0rem");
		$(".bsimg p").css("top", "8%")
		$(".bsimg img").attr("src", $(".allpeople_Tex img").eq(src).attr("src"));
		var wid = $(".allpeople_Tex img").eq(src).height();
		var wids = $(".bsimg").height();
		$(".bsimg").css("display", "block");
		$(".bsimg p").css("opcity", "1");
		if (wid < wids) {
			var hei = wids - wid;
			$(".bsimg p").css("top", "" + ((hei / 2) / 16 + 4) + "rem")
			$(".bsimg img").css("margin-top", "" + (hei / 2) / 16 + "rem");
		}
		time();
	})
	//双击取消
	var i = 0;
	$(".bsimg").on("click", "img", function() {
		i++;
		setTimeout(function() {
			i = 0;
		}, 500);
		if (i > 1) {
			$(".bsimg").css("display", "none");
			i = 0;
		}
	})

	apiready = function() {
		var _user = _getPrefs('_token');
		console.log(_user)
		urlsa();
		_ajax1("agent/index", function(ret, err) {
			// alert(JSON.stringify(ret))
			console.log(JSON.stringify(ret))
			if (ret) {
				if (ret.ret.agent == 0) {
					$(".main").css("display", "block");
				} else {
					window.location.href = "mechanism.html?na=" + ret.ret.agent;
				}
			} else {
				$(".main").css("display", "block");
			}
		})
		_ajax('member/vip_money', function(ret, err) {
			// console.log(JSON.stringify(ret));
			if (ret) {
				$(".btnsuer small").text("(￥" + ret[0].money + "元)");
			}
		})
		api.addEventListener({
			name: '_pay'
		}, function(ret, err) {
			_alert(ret.value.msg)
			_close()
		});
		$(".btnsuer").on("click", function() {
			var ind = $(".picls img[as=a]").index();
			_ajax('member/vip_money', function(ret, err) {
				// console.log(JSON.stringify(ret))
				if (ret) {
					money = ret[ind].money;
					time = ret[ind].time;
					ids = ret[ind].id;
					pay(money, ids, time);
				}


			})
			return;
		})
	}

	function pay(money, id, time) {
		if (_getPrefs('_config').pay.alipay == 1 && _getPrefs('_config').pay.weixin == 1) {
			var buttons = ['支付宝', '微信'];
			var channel = ['ALI_APP', 'WX_APP'];
		} else if (_getPrefs('_config').pay.alipay == 1) {
			var buttons = ['支付宝'];
			var channel = ['ALI_APP']
		} else if (_getPrefs('_config').pay.weixin == 1) {
			var buttons = ['微信'];
			var channel = ['WX_APP']
		} else {
			return _msg('支付未开放，敬请期待！');
		}
		api.actionSheet({
			title: '选择支付方式',
			cancelTitle: '取消',
			buttons: buttons
		}, function(ret, err) {
			var index = ret.buttonIndex;
			var data = {};
			data.money = money * 100;
			data.type = 2;
			data.vip_pay_id = id;
			data.time = time;
			if (channel.length + 1 == index) {
				return _msg('支付取消');
			}
			data.channel = channel[index - 1];
			_pay(data);
		});
	}

	function pays(data) {
		return _msg('支付未开通配置 请在后台支付配置！');
		_loading('正在请求')
		_ajax('member/pay_code', function(ret, err) {
			_loadingCloes()
			if (ret) {
				if (ret.ret) {
					// 判断结束
					var payData = {
						title: '用户(ID' + _user.id + ')购买' + data.time + '天VIP特权',
						totalfee: data.money,
						billno: ret.ret,
						channel: data.channel,
						optional: {
							uid: _user.id,
							payname: '购买VIP',
							type: data.type,
							vip_pay_id: data.vip_pay_id
						}
					};
					beecloud.pay(payData, payCallBack);

					function payCallBack(ret, err) {
						_heibai();
						if (ret) {
							if (ret.result_code == 0) {
								if (ret.result_msg == '支付成功') {
									_loading();
									_ajax('member/info', function(ret, err) {
										_loadingCloes();
										if (ret) {
											_setPrefs('_user', ret);
										}
										_data();
										var url = $(".pic[as=a]").index();
										window.location.href = "mechanism.html?type=" + url;
										// return _alert('恭喜成功购买' + data.time + '天VIP特权')
									})
								}
							} else if (ret.errMsg) {
								_alert(JSON.stringify(ret))
							} else {
								_msg(ret.result_msg)
							}
						} else {
							_alert(JSON.stringify(err))
						}
					}
				} else {
					_alert('ret.err:' + ret.err)
				}
			} else {
				_alert(JSON.stringify(err))
			}
		}, data)

	}
</script>
